var assert = require('assert'),
    util = require('util'),
    user = require('../model/UserModel'),
    item = require('../model/ItemModel'),
    order = require('../model/OrderModel');

describe('Model unit test.', function() {
    /**
     * 对UserModel进行单元测试
     * 
     */
    describe('User model unit test.', function() {
        it('#isValid() should return a valid user.', function(done) {
            user.isValid({name: 'test', password: 'test'}, function(err, user) {
                should.not.exist(err);
                assert.notEqual(user.name, '');
                done();
            });
        });
        it('#updatePassword() should return effect rows.', function(done) {
            user.updatePassword({pwd: 'newpwd', id: 1}, function(err, effect) {
                should.not.exist(err);
                assert.equal(isNaN(effect), true);
                done();
            });
        });
    });
    /**
     * 对ItemModel进行单元测试
     * 
     */
    describe('Item model unit test.', function() {
        it('#listByShop() should return a item list.', function(done) {
            item.listByShop({id: 1}, function(err, itemList) {
                should.not.exist(err);
                assert.equal(util.isArray(itemList), true);
                done();
            });
        });
        it('#add() should return insert id.', function(done) {
            var testItem = {};
            item.add(testItem, function(err, result) {
                should.not.exist(err);
                assert.equal(isNaN(result.inserId), true);
                done();
            });
        });
    });
    /**
     * 对OrderModel进行单元测试
     * 
     */
    describe('Order model unit test.', function() {
        it('#listByShop() should return order list.', function(done) {
            var testOption = {};
            order.listByShop(testOption, function(err, orderList) {
                should.not.exist(err);
                assert.equal(util.isArray(orderList), true);
                done();
            });
        });
        it('#listByUser() should return order list.', function(done) {
            var testOption = {};
            order.listByShop(testOption, function(err, orderList) {
                should.not.exist(err);
                assert.equal(util.isArray(orderList), true);
                done();
            });
        });
        it('#add() should return insert id', function(done) {
            var testOrder = {};
            order.add(testOrder, function(err, result) {
                should.not.exist(err);
                assert.equal(isNaN(result.inserId), true);
                done();
            });
        });

    });

});